﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BussinessLayer;

namespace projectQLDV
{
    public partial class frmDoiMatKhau : DevExpress.XtraEditors.XtraForm
    {
        tblTaikhoan tblTk=new tblTaikhoan();
        MD5Hash md5hash = new MD5Hash();
        private frmMain frmM;
        private string  _TK;
        public frmDoiMatKhau(frmMain frm,string _taikhoan)
        {
            InitializeComponent();
            frmM = frm;
            _TK = _taikhoan;
            showform();
        }

        private void frmDoiMatKhau_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmM.frmDoiMatKhau_isShown = false;
        }
        public void showform()
        {
            txtTaikhoan.Text = _TK;
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void txtLuu_Click(object sender, EventArgs e)
        {
            if (txtMatkhau.Text == "" || txtNhaclaiMK.Text == "")
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Chưa nhập đầy đủ thông tin", "Chú Ý", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (txtMatkhau.Text != txtNhaclaiMK.Text)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("Kiểm tra lại mật khẩu mới", "Chú Ý", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtMatkhau.Text = "";
                    txtNhaclaiMK.Text = "";
                }
                else
                {
                    string _matkhauMahoa = md5hash.CalculateMD5Hash(txtMatkhau.Text);
                    //update mật khẩu type=2
                    tblTk.updateMatKhau(txtTaikhoan.Text, _matkhauMahoa);
                    DevExpress.XtraEditors.XtraMessageBox.Show("Đổi mật khẩu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
        }
    }
}